package com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.view;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.fgs.common.utils.ToastUtil;
import com.fgs.common.widget.itemView.InputItemView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.hetong.ContractInfo;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.IContractType;
import com.tianhui.consignortwofei.mvp.ui.activity.hetong.other.IContractTypeView;


/**
 * @author fgs
 * @date 2021/7/20
 * @description
 **/
public class AdvancePaymentView extends LinearLayout implements IContractTypeView {
    private IContractType iContractType;
    private View contentView;
    private InputItemView dayInputItemView;
    private InputItemView overdueStorageFeeInputItemView;

    public AdvancePaymentView(Context context, IContractType iContractType) {
        super(context);
        this.iContractType = iContractType;
        initView();
    }

    private void initView() {
        contentView = LayoutInflater.from(getContext()).inflate(R.layout.layout_advance_payment_view, null);
        dayInputItemView = contentView.findViewById(R.id.layout_advance_payment_view_dayInputItemView);
        overdueStorageFeeInputItemView = contentView.findViewById(R.id.layout_advance_payment_view_overdueStorageFeeInputItemView);

    }

    @Override
    public ContractInfo getContractViewInfo(ContractInfo contractInfo) {
        String day = dayInputItemView.getContent();
        if (TextUtils.isEmpty(day)) {
            showToast("请输入需方付款天数");
            return null;
        }
        contractInfo.qiandingri = day;

        String overdueStorageFee = overdueStorageFeeInputItemView.getContent();
        if (TextUtils.isEmpty(overdueStorageFee)) {
            showToast("请输入逾期仓储费");
            return null;
        }
        contractInfo.cangchufei = overdueStorageFee;

        String contractContent = iContractType.getContractContent();
        contractInfo.content = contractContent;
        return contractInfo;
    }

    @Override
    public View getContractView() {
        return contentView;
    }

    @Override
    public void initViewData(ContractInfo contractInfo) {
        dayInputItemView.setContent(contractInfo.qiandingri);
        overdueStorageFeeInputItemView.setContent(contractInfo.cangchufei);
    }

    private void showToast(String message) {
        ToastUtil.showShortToast(message);
    }
}
